package qc.module.platform.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qc.common.core.exception.QCPromptException;
import qc.common.core.tree.TreeDataDto;
import qc.module.platform.dto.menu.*;
import qc.module.platform.service.MenusService;

import java.util.List;

/**
 * MenuController
 *
 * @author QuCheng Tech
 * @create 2023/1/9
 */
@RestController
@RequestMapping("/menu")
public class MenuController {
    private MenusService menusService;

    @Autowired
    public void setMenusService(MenusService menusService) {
        this.menusService = menusService;
    }

    //是否为逻辑删除，为true表示逻辑删除--修改记录标记，为false表示物理删除--从数据库表中删除记录
    private static final boolean isLogicDelete = false;

    /**
     * 查询简要菜单信息列表返回，根据条件查询
     *
     * @param condition 查询条件DTO
     * @return 返回简要菜单信息列表
     * @author QuCheng Tech
     * @since 2023/6/30
     */
    @RequestMapping(value = "/listsimple", method = {RequestMethod.GET, RequestMethod.POST})
    public List<MenuSimpleDto> queryListSimple(@RequestBody MenuQueryConditionDto condition) throws QCPromptException {
        return menusService.queryListSimple(condition);
    }

    /**
     * 查询简要菜单信息树形返回，根据条件查询
     *
     * @param condition 查询条件DTO
     * @return 返回简要菜单信息树形结构
     * @author QuCheng Tech
     * @since 2023/6/30
     */
    @RequestMapping(value = "/treesimple", method = {RequestMethod.GET, RequestMethod.POST})
    public List<MenuTreeSimpleDto> queryTreeSimple(@RequestBody MenuQueryConditionDto condition) throws QCPromptException {
        return menusService.queryTreeSimple(condition);
    }

    /**
     * 查询详细菜单信息列表返回，根据条件查询
     *
     * @param condition 查询条件DTO
     * @return 返回详细菜单信息列表
     * @author QuCheng Tech
     * @since 2023/6/30
     */
    @RequestMapping(value = "/listdetail", method = {RequestMethod.GET, RequestMethod.POST})
    public List<MenuDto> queryListDetail(@RequestBody MenuQueryConditionDto condition) throws QCPromptException {
        return menusService.queryListDetail(condition);
    }

    /**
     * 查询详细菜单信息树形返回，根据条件查询
     *
     * @param condition 查询条件DTO
     * @return 返回详细菜单信息树形结构
     * @author QuCheng Tech
     * @since 2023/6/30
     */
    @RequestMapping(value = "/treedetail", method = {RequestMethod.GET, RequestMethod.POST})
    public List<MenuTreeDto> queryTreeDetail(@RequestBody MenuQueryConditionDto condition) throws QCPromptException {
        return menusService.queryTreeDetail(condition);
    }

    /**
     * 查询详细菜单信息树形返回，根据条件查询
     *
     * @param condition 查询条件DTO
     * @return 返回详细菜单信息树形结构
     * @author QuCheng Tech
     * @since 2023/6/30
     */
    @RequestMapping(value = "/treetable", method = {RequestMethod.GET, RequestMethod.POST})
    public List<MenuTreeTableDetailDto> queryTreeTable(@RequestBody MenuQueryConditionDto condition) throws QCPromptException {
        return menusService.queryTreeTableDetail(condition);
    }

    /**
     * 获取指定菜单详情
     *
     * @param id 菜单id
     * @return 返回菜单详情
     * @author QuCheng Tech
     * @since 2023/6/30
     */
    @RequestMapping(value = "/get", method = {RequestMethod.GET})
    public MenuDto getByParam(@RequestParam Integer id) throws QCPromptException {
        return menusService.get(id);
    }

    /**
     * 获取指定菜单详情
     *
     * @param id 菜单id
     * @return 返回菜单详情
     * @author QuCheng Tech
     * @since 2023/6/30
     */
    @RequestMapping(value = "/get/{id}", method = {RequestMethod.GET})
    public MenuDto getByPath(@PathVariable Integer id) throws QCPromptException {
        return menusService.get(id);
    }

    /**
     * 新增菜单信息
     *
     * @param dto 菜单信息
     * @return 成功返回null
     * @author QuCheng Tech
     * @since 2023/6/30
     */
    @RequestMapping(value = "/add", method = {RequestMethod.POST})
    public String add(@RequestBody MenuDto dto) {
        return menusService.add(dto);
    }

    /**
     * 修改菜单信息
     * <p>
     * 可修改启用状态
     *
     * @param dto 菜单信息
     * @return 成功返回null
     * @author QuCheng Tech
     * @since 2023/6/30
     */
    @RequestMapping(value = "/update", method = {RequestMethod.PUT, RequestMethod.POST})
    public String update(@RequestBody MenuDto dto) {
        return menusService.update(dto);
    }

    /**
     * 删除菜单信息
     * <p>
     * 需要同步删除角色和菜单的关联关系
     *
     * @param id 菜单id
     * @return 成功返回null
     * @author QuCheng Tech
     * @since 2023/6/30
     */
    @RequestMapping(value = "/delete", method = {RequestMethod.DELETE})
    public String deleteByParam(@RequestParam Integer id) {
        return menusService.delete(id, isLogicDelete);
    }

    /**
     * 删除菜单信息
     * <p>
     * 需要同步删除角色和菜单的关联关系
     *
     * @param id 菜单id
     * @return 成功返回null
     * @author QuCheng Tech
     * @since 2023/6/30
     */
    @RequestMapping(value = "/delete/{id}", method = {RequestMethod.DELETE})
    public String deleteByPath(@PathVariable Integer id) {
        return menusService.delete(id, isLogicDelete);
    }

    /**
     * 获取菜单API关联关系
     * 
     * @param id 菜单ID
     * @return List<MenuAPIDto>
     * @author QuCheng Tech
     * @since 2024/5/8
     */
    @RequestMapping(value = "/getapis",method = {RequestMethod.GET})
    public List<MenuAPIDto> getMenuApisByParam(@RequestParam Integer id){
        return menusService.getMenuApis(id);
    }

    /**
     * 获取菜单API关联关系
     *
     * @param id 菜单ID
     * @return List<MenuAPIDto>
     * @author QuCheng Tech
     * @since 2024/5/8
     */
    @RequestMapping(value = "/getapis/{id}",method = {RequestMethod.GET})
    public List<MenuAPIDto> getMenuApisByPath(@PathVariable Integer id){
        return menusService.getMenuApis(id);
    }

    /**
     * 以树形结构返回结果，按Api接口分组分2级列出所有接口；
     *
     * @param id: 菜单id
     * @return TreeDataDto 返回结果集
     * @author QcCheng Tech
     * @date 2024/5/10
     */
    @RequestMapping(value = "/getapistree",method = {RequestMethod.GET})
    public TreeDataDto getMenuApisTreeByParam(@RequestParam Integer id) throws QCPromptException {
        return menusService.getMenuApisTree(id);
    }

    /**
     * 以树形结构返回结果，按Api接口分组分2级列出所有接口；
     *
     * @param id: 菜单id
     * @return TreeDataDto 返回结果集
     * @author QcCheng Tech
     * @date 2024/5/10
     */
    @RequestMapping(value = "/getapistree/{id}",method = {RequestMethod.GET})
    public TreeDataDto getMenuApisTreeByPath(@PathVariable Integer id) throws QCPromptException {
        return menusService.getMenuApisTree(id);
    }
    

    /**
     * 设置菜单API关联关系
     * 
     * @param dto
     * @return 成功返回null，失败返回错误或提示信息
     * @author QuCheng Tech
     * @since 2024/5/8
     */
    @RequestMapping(value = "/setapis",method = {RequestMethod.GET,RequestMethod.POST})
    public String setMenuApis(@RequestBody MenuAPISetDto dto){
        return menusService.setMenuApis(dto);
    }
    
}
